30 #ifndef __LOW_POWER_DEMO_H__
31 #define __LOW_POWER_DEMO_H__
34 #include "uart/fsl_uart_driver.h"
35 #include "smc/fsl_smc_manager.h"
36 #include "fsl_mcg_hal.h"
44 #define CLK0_TYPE CRYSTAL
48 #define SWD_CLK_DISABLE port_hal_mux_control(HW_PORTA, 0, kPortPinDisabled)
49 #define SWD_DIO_DISABLE port_hal_mux_control(HW_PORTA, 3, kPortPinDisabled)
51 #define SWD_CLK_ENABLE port_hal_mux_control(HW_PORTA, 0, kPortMuxAlt7)
52 #define SWD_DIO_ENABLE port_hal_mux_control(HW_PORTA, 3, kPortMuxAlt7)
55 #if defined(FRDM_KL25Z48M)
72 #define LED0_EN (port_hal_mux_control(HW_GPIOD, 4, kPortMuxAsGpio))
73 #define LED1_EN (port_hal_mux_control(HW_GPIOD, 5, kPortMuxAsGpio))
74 #define LED2_EN (port_hal_mux_control(HW_GPIOD, 6, kPortMuxAsGpio))
75 #define LED3_EN (port_hal_mux_control(HW_GPIOD, 7, kPortMuxAsGpio))
77 #define LED0_OFF (gpio_write_pin_output(ledPins[0].pinName, 1))
78 #define LED1_OFF (gpio_write_pin_output(ledPins[1].pinName, 1))
79 #define LED2_OFF (gpio_write_pin_output(ledPins[2].pinName, 1))
80 #define LED3_OFF (gpio_write_pin_output(ledPins[3].pinName, 1))
82 #define LED0_ON (gpio_write_pin_output(ledPins[0].pinName, 0))
83 #define LED1_ON (gpio_write_pin_output(ledPins[1].pinName, 0))
84 #define LED2_ON (gpio_write_pin_output(ledPins[2].pinName, 0))
85 #define LED3_ON (gpio_write_pin_output(ledPins[3].pinName, 0))
99 #define UNDEF_VALUE 0xFF
112 #define LLWU_PIN_DIS 0
113 #define LLWU_PIN_RISING 1
114 #define LLWU_PIN_FALLING 2
115 #define LLWU_PIN_ANY 3
118 #define LPTMR_USE_IRCLK 0
119 #define LPTMR_USE_LPOCLK 1
120 #define LPTMR_USE_ERCLK32 2
121 #define LPTMR_USE_OSCERCLK 3
124 #if (defined(TWR_K22F120M) || defined(FRDM_K22F120M))
125 #define CLK0_FREQ_HZ 8000000
126 #elif (defined(FRDM_K64F120M) || defined(TWR_K64F120M))
127 #define CLK0_FREQ_HZ 50000000
137 #define MCG_OUT_FREQ 48000000
139 #if defined(CPU_MK22FN512VDC12)
140 #define OSC0_CR OSC_CR
141 #define SMC_STOPCTRL_VLLSM_MASK SMC_STOPCTRL_LLSM_MASK
144 #if defined(CPU_MKL25Z128VLK4)
145 #define sysinit SystemInit
178 void llwu_configure(uint32_t pinEn, uint8_t riseFall, uint8_t moduleEn );
180 void lptmr_init(uint32_t count, uint32_t clockSource);
183 void enter_stop(smc_stop_submode_t partialStopOpt);
193 uint8_t
atc(uint8_t ircSelect, int32_t ircFreq, int32_t mcgOutFreq);
195 int32_t
fee_fei(int32_t slowIrcFreqInner);
196 int32_t
fei_fbe(int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal);
198 int32_t
fei_fbi(int32_t ircFreq, uint8_t ircSelect);
199 int32_t
fbi_fei(int32_t slowIrcFreqInner);
200 int32_t
fbe_pbe(int32_t crystalVal, int8_t prDivVal, int8_t vDivVal);
201 int32_t
pbe_pee(int32_t crystalVal);
202 int32_t
pee_pbe(int32_t crystalVal);
203 int32_t
pbe_fbe(int32_t crystalVal);
204 int32_t
fbe_fbi(int32_t ircFreq, uint8_t ircSelect);
205 int32_t
fbi_fbe(int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal);
206 int32_t
fbi_fee(int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal);
207 int32_t
fbe_fee(int32_t crystalVal);
208 int32_t
fee_fbe(int32_t crystalVal);
209 int32_t
pbe_blpe(int32_t crystalVal);
210 int32_t
blpe_pbe(int32_t crystalVal, int8_t prDivVal, int8_t vDivVal);
211 int32_t
blpe_fbe(int32_t crystalVal);
212 int32_t
fbi_blpi(int32_t ircFreq, uint8_t ircSelect);
213 int32_t
blpi_fbi(int32_t ircFreq, uint8_t ircSelect);
214 int32_t
fei_fee(int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal);
215 int32_t
fee_fbi(int32_t ircFreq, uint8_t ircSelect);
216 int32_t
fbe_blpe(int32_t crystalVal);
217 int32_t
pll_init(int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal, int8_t prDivVal, int8_t vDivVal, uint8_t mcgOutSelect);
int32_t fbi_fbe(int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal)
switches from FBI to FBE mode
Definition: low_power_demo.c:2685
int32_t pbe_fbe(int32_t crystalVal)
switches from PBE to FBE mode
Definition: low_power_demo.c:2094
void get_uart_data(uart_state_t *uartState, uint8_t *rxBuffer, uint32_t requestedByteCount)
void demo_lptmr_isr(void)
ISR Routine for Low Power Timer.
Definition: low_power_demo.c:1221
void enter_vlls1(void)
VLLS1 mode entry routine. Puts the processor into VLLS1 mode from normal run mode or VLPR...
Definition: low_power_demo.c:594
int32_t fbe_fei(int32_t slowIrcFreq)
int32_t pee_pbe(int32_t crystalVal)
switches from PEE to PBE mode
Definition: low_power_demo.c:1993
void vlp_clock_config(int8_t nextMode)
clock configuration for very low power
Definition: low_power_demo.c:874
void llwu_configure(uint32_t pinEn, uint8_t riseFall, uint8_t moduleEn)
Set up the LLWU for wakeup the MCU from LLS and VLLSx modes from the selected pin or module...
Definition: llwu_MK22F51212.c:69
int32_t fbe_fbi(int32_t ircFreq, uint8_t ircSelect)
switches from FBE to PLPE mode
Definition: low_power_demo.c:2564
int32_t fee_fbi(int32_t ircFreq, uint8_t ircSelect)
switches from FEE to FBI mode
Definition: low_power_demo.c:2894
int32_t fee_fbe(int32_t crystalVal)
switches from FEE to FBE mode
Definition: low_power_demo.c:2526
int32_t fbe_fee(int32_t crystalVal)
int32_t blpe_to_pee(void)
switch from BLPE mode to PEE mode
Definition: low_power_demo.c:395
void lptmr_init(uint32_t count, uint32_t clockSource)
Low Power Timer initialization routine.
Definition: low_power_demo.c:1247
static void init_hardware(void)
Init hardware for TWR-K70F120M.
Definition: flexcan_demo/src/main.c:95
void enter_vlls3(void)
enter in VLLS3 mode
Definition: low_power_demo.c:653
int32_t fee_fei(int32_t slowIrcFreqInner)
switches from
Definition: low_power_demo.c:3306
int32_t fll_freq(int32_t fllRef)
returns the Frequency Locked Loop frequency
Definition: low_power_demo.c:224
void out_srs(void)
checks the value in the SRS registers and sends messages to the terminal announcing the status at the...
Definition: low_power_demo.c:3713
int32_t fbe_pbe(int32_t crystalVal, int8_t prDivVal, int8_t vDivVal)
switches from FBE to PBE mode This function transitions the MCG from FBE mode to PBE mode...
Definition: low_power_demo.c:2144
int32_t pbe_pee(int32_t crystalVal)
switches from PBE to PEE mode
Definition: low_power_demo.c:2034
void enter_vlps(void)
enter in VLPS mode
Definition: low_power_demo.c:639
int32_t fei_fee(int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal)
switches from FEI to FEE mode
Definition: low_power_demo.c:3178
int32_t fbe_blpe(int32_t crystalVal)
switches from FBE to PLPE mode
Definition: low_power_demo.c:2363
int32_t enter_vlpr(void)
VLPR mode entry routine.Puts the processor into very low power run mode. In this mode all clocks are ...
Definition: low_power_demo.c:750
int32_t blpe_pbe(int32_t crystalVal, int8_t prDivVal, int8_t vDivVal)
switches from BLPE to PBE mode Since PBE mode can be enterred via FBE -> BLPE modes, it cannot be assumed that the PLL has been previously configured correctly. That is why this general purpose driver has the PLL settings as passed parameters.
Definition: low_power_demo.c:2251
int32_t pee_to_blpe(void)
switch from PEE mode to BLPE mode
Definition: low_power_demo.c:380
void port_isr(void)
Port ISR routine for the on board switch.
Definition: low_power_demo.c:3792
int32_t pbe_blpe(int32_t crystalVal)
switches from PBE to BLPE mode
Definition: low_power_demo.c:2221
uint8_t atc(uint8_t ircSelect, int32_t ircFreq, int32_t mcgOutFreq)
configure for MCG auto trimming
Definition: low_power_demo.c:3363
int32_t fbi_fee(int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal)
int32_t blpi_fbi(int32_t ircFreq, uint8_t ircSelect)
switches from BLPI to FBI mode
Definition: low_power_demo.c:2861
int32_t fei_fbi(int32_t ircFreq, uint8_t ircSelect)
switches from FEI to FBI mode
Definition: low_power_demo.c:3071
void clock_monitor(uint8_t enable)
int32_t fei_fbe(int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal)
switches from FEI to FBE mode
Definition: low_power_demo.c:2399
static uart_state_t uartState
Definition: low_power_demo.c:66
uint8_t what_mcg_mode(void)
returns the the current MCG mode
Definition: low_power_demo.c:300
int32_t slowIrcFreq
Definition: low_power_demo.c:70
void set_for_lp(uint8_t outOfLp)
Settings done before swithing in low power mode.
Definition: low_power_demo.c:416
static sai_data_format_t * format
Definition: modulator.c:60
void low_power_modes_test(void)
main low power mode test routine
Definition: low_power_demo.c:1316
void enter_lls(void)
LLS mode entry routine. Puts the processor into LLS mode from normal run mode or VLPR.
Definition: low_power_demo.c:681
void enter_stop(smc_stop_submode_t partialStopOpt)
STOP mode entry routine. Puts the processor into normal stop mode. In this mode core, bus and peripheral clocks are disabled.
Definition: low_power_demo.c:859
void llwu_init(void)
initializes LLWU module
Definition: low_power_demo.c:1290
void jtag_tdo_pullup_enable(void)
int32_t blpe_fbe(int32_t crystalVal)
switches from BLPE to FBE mode
Definition: low_power_demo.c:2326
void led_init(void)
configure LED pins for the tower/freedom hardware
Definition: low_power_demo.c:209
int32_t fbi_blpi(int32_t ircFreq, uint8_t ircSelect)
switches from FBI to BLPI mode This function transitions the MCG from FBI mode to BLPI mode...
Definition: low_power_demo.c:2819
void port_init(void)
configure tower/freedom hardware port pins for the application
Definition: low_power_demo.c:140
void enter_vlls0(uint8_t PORPOValue)
VLLS0 mode entry routine. Puts the processor into VLLS0 mode from normal run mode or VLPR...
Definition: low_power_demo.c:563
int printf_demo(const char *format,...)
void enter_vlls2(void)
VLLS2 mode entry routine. Puts the processor into VLLS2 mode from normal run mode or VLPR...
Definition: low_power_demo.c:624
void enter_wait(power_modes_t pMode)
WAIT mode entry routine. Puts the processor into wait mode. In this mode the core clock is disabled (...
Definition: low_power_demo.c:827
int32_t fbi_fei(int32_t slowIrcFreqInner)
switches from FBI to FEI mode
Definition: low_power_demo.c:3006
void exit_vlpr(void)
VLPR mode exit routine. Puts the processor into normal run mode from VLPR mode. You can transition fr...
Definition: low_power_demo.c:701
int32_t pll_init(int32_t crystalVal, mcg_hgo_select_t hgoVal, mcg_eref_clock_select_t erefsVal, int8_t prDivVal, int8_t vDivVal, uint8_t mcgOutSelect)
Option to move from FEI to PEE mode or to just initialize the PLL.
Definition: low_power_demo.c:3506